package com.cloud.phone.utils

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.view.View
import com.cloud.phone.base.BaseActivity
import com.cloud.phone.base.BaseApp
import com.cloud.phone.constants.Constants
import com.cloud.phone.view.NoDoubleClickListener
import com.cloud.phone.view.TipsDialog

/**
 * @auth: njb
 * @date: 2024/6/12 11:56
 * @desc: 描述
 */
class PermissionUtils {
    companion object {

        @SuppressLint("StaticFieldLeak")
        private var msgDialog: TipsDialog? = null


        fun showOpenAccessibilityTips(context: Context) {
            // 判断服务是否开启
            if (msgDialog != null && msgDialog!!.isShowing) {
                msgDialog!!.dismiss()
                msgDialog = null
            }
            msgDialog = TipsDialog(context)
            msgDialog!!.setCancelable(true)
            msgDialog!!.getHolder().tvSure.text = "去开启"
            msgDialog!!.getHolder().tvcancel.visibility = View.VISIBLE
            msgDialog!!.getHolder().tvContent.text =
                "使用此功能需要开启无障碍服务，请点击去开启手动打开！"
            msgDialog!!.getHolder().tvSure.setOnClickListener(object : NoDoubleClickListener() {
                override fun onNoDoubleClick(v: View?) {
                    msgDialog!!.dismiss()
                    jumpToSettingPage(context) // 跳转到开启页面
                }
            })
            msgDialog!!.show()
        }

        //跳转到设置页面无障碍服务开启自定义辅助功能服务
        fun jumpToSettingPage(context: Context) {
            val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        }

        @JvmStatic
        fun startService() {
            if (!Constants.isServiceApplication) {
                if (!Settings.canDrawOverlays(BaseApp.app.applicationContext)) {
                    BaseActivity().requestOverlayPermission()
                    return
                }
            }
        }



    }
}